<template>
    <div style="padding: 10px;">
        <el-form :model="formData" ref="queryForm" class="queryForm" :inline="true" :rules="Rules" label-width="auto"
                 @submit.native.prevent>
            
            <el-form-item label="对应字段名" desc="对应字段名" prop="fieldName">
                <el-input v-model.trim="formData.fieldName" placeholder="对应字段名" clearable size="small"
                          style="width:120px;" />
            </el-form-item>
            
            
            <el-form-item label="对应字段类型" desc="对应字段类型 1文本  2单选框  3多选框  4下拉框 " prop="fieldType">
                <dic-select v-model="formData.fieldType" :code="dicInner.mes_bpm_form_fieldType"
                            placeholder="对应字段类型 1文本  2单选框  3多选框  4下拉框 " clearable size="small" style="width:120px;" />
            </el-form-item>
            <!--    <el-form-item label="对应字段值" desc="对应字段值" prop="fieldValue">
                    <el-input v-model.trim="formData.fieldValue" placeholder="对应字段值" clearable size="small"
                              style="width:120px;" />
                </el-form-item>-->
            <el-form-item label="字段编码" desc="字段编码" prop="fieldCode">
                <el-input v-model.trim="formData.fieldCode" placeholder="字段编码" clearable size="small"
                          style="width:120px;" />
            </el-form-item>
            <el-form-item label="排序号" desc="排序号" prop="orderNum">
                <el-input-number v-model.trim="formData.orderNum" placeholder="排序号" clearable size="small"
                                 style="width:120px;" />
            </el-form-item>
            <el-form-item label="状态" desc="状态 1 正常  5暂停 10废除" prop="state">
                <dic-select v-model="formData.state" :code="dicInner.mes_bpm_form_state" placeholder="状态 1 正常  5暂停 10废除"
                            clearable size="small" style="width:120px;" />
            </el-form-item>
            
            <div>
                <el-form-item label="下拉值" desc="下拉值" prop="state">
                    <el-input v-model="formData.valueList"  type="textarea"
                                clearable size="small" style="width:420px;"
                                 :rows="5"
                                />
                </el-form-item>
            </div>
        </el-form>
    </div>
</template>
<script>  import { getUrlParam } from '@/utils/index';
import * as  api from '@/apis/mesBpmForm.api.js';
import { alertWithPaylod } from '@/utils/alertUtil';
import { fillData, validatePromise } from '@/utils';

const Rules = {
  'id': [{ required: false, message: '主键ID', trigger: 'blur' }],
  'bpmId': [{ required: false, message: '对应生产计划单id', trigger: 'blur' }],
  'formType': [{ required: false, message: '1打版', trigger: 'blur' }],
  'fieldName': [{ required: true, message: '对应字段名', trigger: 'blur' }],
  'fieldType': [{ required: true, message: '对应字段类型', trigger: 'blur' }],
  'fieldValue': [{ required: false, message: '对应字段值', trigger: 'blur' }],
  'fieldCode': [{ required: false, message: '字段编码', trigger: 'blur' }],
  'orderNum': [{ required: false, message: '排序号', trigger: 'blur' }],
  'state': [{ required: false, message: '状态', trigger: 'blur' }],
  'remarks': [{ required: false, message: '备注', trigger: 'blur' }],
  'tenantType': [{ required: false, message: '租户类型', trigger: 'blur' }],
  'tenantId': [{ required: false, message: '租户ID', trigger: 'blur' }],
  'delState': [{ required: false, message: '有效状态[数据字典=del_state]', trigger: 'blur' }],
  'addUser': [{ required: false, message: '添加人', trigger: 'blur' }],
  'addUserId': [{ required: false, message: '添加人ID', trigger: 'blur' }],
  'addTime': [{ required: false, message: '添加时间', trigger: 'blur' }],
  'editUser': [{ required: false, message: '最近更新人', trigger: 'blur' }],
  'editUserId': [{ required: false, message: '最近更新人ID', trigger: 'blur' }],
  'lastEditTime': [{ required: false, message: '最近更新时间', trigger: 'blur' }],
  'serverNumber': [{ required: false, message: '服务器编号ID', trigger: 'blur' }],
};
const dicInner = {
  '___mes_bpm_form_id': '主键ID',
  'mes_bpm_form_id': 'mes_bpm_form_id',
  '___mes_bpm_form_bpmId': '对应生产计划单id',
  'mes_bpm_form_bpmId': 'mes_bpm_form_bpmId',
  '___mes_bpm_form_formType': '1打版',
  'mes_bpm_form_formType': 'mes_bpm_form_formType',
  '___mes_bpm_form_fieldName': '对应字段名',
  'mes_bpm_form_fieldName': 'mes_bpm_form_fieldName',
  '___mes_bpm_form_fieldType': '对应字段类型 1文本  2单选框  3多选框  4下拉框 ',
  'mes_bpm_form_fieldType': 'mes_bpm_form_fieldType',
  '___mes_bpm_form_fieldValue': '对应字段值',
  'mes_bpm_form_fieldValue': 'mes_bpm_form_fieldValue',
  '___mes_bpm_form_fieldCode': '字段编码',
  'mes_bpm_form_fieldCode': 'mes_bpm_form_fieldCode',
  '___mes_bpm_form_orderNum': '排序号',
  'mes_bpm_form_orderNum': 'mes_bpm_form_orderNum',
  '___mes_bpm_form_state': '状态 1 正常  5暂停 10废除',
  'mes_bpm_form_state': 'mes_bpm_form_state',
  '___mes_bpm_form_remarks': '备注',
  'mes_bpm_form_remarks': 'mes_bpm_form_remarks',
  '___mes_bpm_form_tenantType': '租户类型 1应用管理者2应用消息者',
  'mes_bpm_form_tenantType': 'mes_bpm_form_tenantType',
  '___mes_bpm_form_tenantId': '租户ID',
  'mes_bpm_form_tenantId': 'mes_bpm_form_tenantId',
  '___mes_bpm_form_delState': '有效状态[数据字典=del_state] 1有效  5删除',
  'mes_bpm_form_delState': 'mes_bpm_form_delState',
  '___mes_bpm_form_addUser': '添加人',
  'mes_bpm_form_addUser': 'mes_bpm_form_addUser',
  '___mes_bpm_form_addUserId': '添加人ID',
  'mes_bpm_form_addUserId': 'mes_bpm_form_addUserId',
  '___mes_bpm_form_addTime': '添加时间',
  'mes_bpm_form_addTime': 'mes_bpm_form_addTime',
  '___mes_bpm_form_editUser': '最近更新人',
  'mes_bpm_form_editUser': 'mes_bpm_form_editUser',
  '___mes_bpm_form_editUserId': '最近更新人ID',
  'mes_bpm_form_editUserId': 'mes_bpm_form_editUserId',
  '___mes_bpm_form_lastEditTime': '最近更新时间',
  'mes_bpm_form_lastEditTime': 'mes_bpm_form_lastEditTime',
  '___mes_bpm_form_serverNumber': '服务器编号ID',
  'mes_bpm_form_serverNumber': 'mes_bpm_form_serverNumber',
};
export default {
  name: 'mesBpmFormlist',
  data() {
    return {
      api: api,
      Rules,
      dicInner,
      formData: {
        valueList: '',
        'id': '',
        'bpmId': '',
        'formType': '',
        'fieldName': '',
        'fieldType': '',
        'fieldValue': '',
        'fieldCode': '',
        'orderNum': '',
        'state': '',
        'remarks': '',
        'tenantType': '',
        'tenantId': '',
        'delState': '',
        'addUser': '',
        'addUserId': '',
        'addTime': '',
        'editUser': '',
        'editUserId': '',
        'lastEditTime': '',
        'serverNumber': '',
      },
      lists: [],
      selectRows: [],
      classId: '',
      classIdPath: '',
      className: '',
      loading: false,
      isFold: false,
      tableRowClassName({ row, rowIndex }) {
        if (row.rowType == 'total') {
          return 'total-row';
        }
        return '';
      },
    };
  },
  components: {
    svgIcon: () => import('@codegenarate/svg-icon'),
    dicSelect: () => import('@/components/dicselect.vue'),
    dicTag: () => import('@/components/DicSelect/dic-tag.vue'),
  },
  computed: {},
  watch: {},
  methods: {
    /**
     *    @params _data.
     *   @desc 初始化
     *     */
    initByDialog(_data) {
      fillData(this.formData, _data);
      /*初始化设置*/
      if(!this.formData.orderNum){
        this.formData.orderNum=1
      }
      if(!this.formData.state){
        this.formData.state=1
      }
      console.log('初始化数据', this.formData);
    },
    async submitByDialog(_data) {
      var isyes = await validatePromise.call(this, 'queryForm');
      if (!isyes) {
        return { success: false, message: '请检查必填项' };
      }
      var func = this.formData?.id ? api.update : api.add;
      var result = await func(this.formData);
      alertWithPaylod(result);
      return result;
    },
  },
};</script>
